<script setup>
import { ref, reactive } from "vue";
import { useRouter } from 'vue-router'
import axios from "axios";
const router = useRouter();
const name = ref("");
const pass = ref("");
const ce=()=>{
    window.location.href = "./home.html";
    
    // console.log(router.getRoutes())
}
const denglu = async () => {
    try {
        const { data } = await axios.get("http://localhost:8080/login", {
            params: {
                name: name.value,
                pass: pass.value
            }
        });
        if (data != 0) {
            alert("登录成功");
            if (confirm("是否进入主页？")) {
                window.location.href = "./data.html";
                ce();
            }
        } else {
            alert("登录失败");
        }
    } catch (error) {
        console.error("请求失败:", error);
    }
}


</script>

<template>
    <div class="a">
        <form>
            <table cellpading="6" cellspacing="0" border="1">
                <tr>
                    <td>用户名：<input type="text" name="name" v-model="name"></td>
                </tr>
                <tr>
                    <td>密码：<input type="text" name="pass" v-model="pass"></td>
                </tr>
                <tr>
                    <td colspan="2" align="center"><button type="button" @click="denglu">登录</button></td>
                </tr>

            </table>
        </form>

    </div>
    <!-- <button type="button" @click="ce">测试多页面</button> -->
</template>

<style scoped>
.a {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  max-width: 450px;
  margin: 5vh auto;
  padding: 2.5rem;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
}

h1 {
  text-align: center;
  color: #2c3e50;
  margin-bottom: 1.5rem;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 1rem;
}

tr {
  transition: all 0.2s ease;
}

td {
  padding: 1rem;
  border: none;
}

input {
  width: calc(100% - 1rem);
  padding: 0.75rem 1rem;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.3s;
  margin: 0 0.5rem 0 0;
}

input:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

button {
  width: 100%;
  background: linear-gradient(135deg, #007bff, #0062cc);
  color: white;
  border: none;
  padding: 0.75rem;
  font-size: 1rem;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}

button:active {
  transform: translateY(0);
}

.forgot-link {
  display: block;
  text-align: center;
  margin-top: 1rem;
  color: #6c757d;
  text-decoration: none;
  font-size: 0.9rem;
}

.forgot-link:hover {
  color: #007bff;
}
</style>
